<template>
  <view class="login">
    <view class="top">
      <view class="login1">登录</view>
      <view class="login2">欢迎来到宠物服务上门</view>
    </view>
    <view class="userlogin">
      <view class="userlogin1">
        <uv-input
          placeholder="请输入您的手机号"
          customStyle="border:none;padding: 2%;"
          v-model="phone"
        ></uv-input>
      </view>
      <view class="userlogin1">
        <uv-input
          placeholder="请输入您的密码"
          customStyle="border:none;padding: 2%;"
          v-model="password"
          type="password"
        ></uv-input>
      </view>
      <view class="determine">
        <uv-button
          type="primary"
          color="#008c8c"
          shape="circle"
          text="确定"
          @click="handleLogin"
        ></uv-button>
      </view>
      <view class="all">
        <view class="left" @click="goPassword">忘记密码</view>
        <view class="right" @click="goRegistered">新用户注册</view>
      </view>
    </view>
  </view>
</template>

<script>
import { uniRequest } from "../../utils/request/request";
export default {
  data() {
    return {
      phone: "18605446224",
      password: "354000",
    };
  },
  methods: {
    handleLogin() {
      const mobile = this.phone;
      const password = this.password;
      console.log("123", mobile, password);
      uniRequest(
        "login/login?server=1",
        function (err, data) {
          if (err) {
            // 错误
            console.log(err);
          } else {
            console.log('"成功了"', data.token);
            const token = data.token;
            uni.setStorageSync("token", token);
            uni.showToast({
              title: "登录成功", // 提示文字
              duration: 2000, // 显示时间，单位ms，默认2秒
              icon: "success",
            });
            uni.switchTab({
              url: "/pages/tabBar/index/index",
            });
          }
        },
        "POST",
        {
          mobile: mobile,
          password: password,
        }
      );
    },
    // 去注册页
    goRegistered() {
      uni.navigateTo({ url: "/pages/registered/registered" });
    },
    // 去密码页
    goPassword() {
      uni.navigateTo({ url: "/pages/password/password" });
    },
  },
};
</script>

<style lang="scss">
@import url("./login.css");
</style>
